6.2.6 - SUI Toggles


What's a toggle?

A toggle in SUI is a checkbox which can do something when it's state it's changed. It's declared as SToggle.

We can add it to a panel or container as usual and specify what to do when the value is changed using the .Notify method. Keep in mind that the specified method must always accept a boolean argument. In the example below when we click the checkbox it will print the state of the checkbox in the RedLoader console.


var panel = RegisterNewPanel("panel id", true).Anchor(AnchorType.MiddleCenter).Background(Color.blue, EBackground.RoundedStandard).Size(1280, 720);
var container = SContainer.Background(Color.green).Anchor(AnchorType.Fill)
                    - SToggle.Text("Checkbox").Notify((bool myBool) => { RLog.Msg(myBool); });

panel.Add(container);
            

Another example could be like so:


public static void Create()
{
    var panel = RegisterNewPanel("panel id", true).Anchor(AnchorType.MiddleCenter).Background(Color.blue, EBackground.RoundedStandard).Size(1280, 720);
    var container = SContainer.Background(Color.green).Anchor(AnchorType.Fill)
                        - SToggle.Text("Checkbox").Notify(SetGodMode); // calling "SetGodMode" method when the checkbox is clicked, passing the state of the checkbox as bool

    panel.Add(container);
}

private static void SetGodMode(bool state)
{
    RLog.Msg(state);
}